; *** Chinese Chess
; *** Copyright 1998-2002 Zillions Development
; v.2.0

; You need to purchase Zillions of Games to load this rules file
; Visit the Zillions web site at http://www.zillions-of-games.com

(define shift-myside   ($1 (verify empty?) $1 (verify not-friend?) (verify (in-zone? myside)) add) )
(define shift-fortress ($1 (verify not-friend?) (verify (in-zone? fortress)) add) )
(define shift2         ($1 (verify empty?) $2 (verify not-friend?) add) )
(define slide          ($1 (while empty? add $1) (verify enemy?) add))
(define slide-cannon   ($1 (while empty? add $1) $1 (while empty? $1) (verify enemy?) add))
(define opposed-kings  (n (while empty? n) (verify (piece? General)) add) )
(translate
 ("Red""红方")("Black""黑方")
 ("Soldier" "兵") ("Horse" "马")
 ("Chariot" "车") ("Elephant" "象")
 ("Cannon" "炮") ("Mandarin" "士")
 ("General" "将")
)
(game
   (title "中国象棋")
   (description "将死敌方将/帅或困毙敌方获胜。\\右键点击棋子查看说明。")
   (history "Chinese Chess, or Xiangqi (Elephant Chess), derives from the same source as
        Western Chess, though there is much debate over whether the earliest form of chess
        began in India or China.   The first definite reference to the game is from the
        8th century; the present form dates from about the beginning of the 12th century.
        Xiangqi is still firmly embedded in culture in China and viewed as a folk game.
        Among the Chinese, the rules are said to be universally known, and it is claimed
        that Xiangqi is the world's most popular game, with perhaps 200 million players.")
   (strategy "Unlike Western Chess, having an extra piece is not as important as having
      a strong attack.  Attack on the General can come at any stage of the game.\\
	  Chariots are the most valuable pieces, being worth about twice as much as a
	  Cannon.   The Horse is slightly less valuable than the Cannon in the opening,
        but becomes stronger as the game progresses, as it becomes more mobile and
        the Cannon less so (due to the lack of `screens`).  Mandarins and Elephants
        are purely defensive pieces.   Soldiers are very weak until they cross the river
        and promote, where their increased mobility makes them useful in attack.\\
        The most common opening moves are: moving either Cannon behind the central
        Soldier, moving a Horse to defend the central Soldier (this also frees the
        Chariot to occupy the adjacent file), pushing a c-file or g-file Soldier to
        give a Horse a path to advance to the river's edge, or bringing either Elephant
        to the front of the fortress to protect its partner.\\
        Endgames have been studied even more deeply than in Western chess, and much
        is known about mating possibilities with various combinations of pieces.
        A lone General can be mated (remember that checkmate and stalemate both win,
        and Generals cannot face each other a file with no intervening pieces) by
        General and Soldier, General and Horse, or General and Chariot.   A Chariot
        can even win against two Elephants or two Mandarins; two Soldiers can defeat
        a single Elephant or two Mandarins.   Many detailed endgame examples are
        given in H. T. Lau's book `Chinese Chess`.\\
        Literature on the game is plentiful in Chinese (and game transcripts can be
        understood with a little study, by learning the characters for the pieces,
        Chinese numbers, and a few miscellaneous characters).    English-language
        sources are less abundant; some good books and magazines can be found at
        <http://www.zillions-of-games.com/xiangqi.html>.")
   (music "Audio\\China.mid")
   (win-sound "Audio\\Pan.wav")
   (loss-sound "Audio\\Pan.wav")
   (opening-sound "Audio\\Pan.wav")
   (release-sound "Audio\\BongPercussive.wav")
   (move-sound "Audio\\Bong5th.wav")
   (capture-sound "Audio\\WoodBells.wav")
   (players Red Black)
   (turn-order Red Black)

   (board
      (image "images\Chinese_Chess\ChineseChess.bmp")
      (grid
         (start-rectangle 4 5 46 47)
         (dimensions
             ("a/b/c/d/e/f/g/h/i" (45 0)) ; files
             ("10/9/8/7/6/5/4/3/2/1" (0 45)) ; ranks
         )
         (directions (n 0 -1) (e 1 0) (s 0 1) (w -1 0)
			         (ne 1 -1) (nw -1 -1) (se 1 1) (sw -1 1)
         )
      )
      (symmetry Black (n s)(s n) (nw sw)(sw nw) (ne se)(se ne))
      (zone
         (name fortress)
         (players Red)
         (positions d1 e1 f1 d2 e2 f2 d3 e3 f3)
      )
      (zone
         (name fortress)
         (players Black)
         (positions d10 e10 f10 d9 e9 f9 d8 e8 f8)
      )
      (zone
         (name myside)
         (players Red)
         (positions a1 b1 c1 d1 e1 f1 g1 h1 i1
		            a2 b2 c2 d2 e2 f2 g2 h2 i2
					a3 b3 c4 d3 e3 f3 g3 h3 i3
					a4 b4 c4 d4 e4 f4 g4 h4 i4
					a5 b5 c5 d5 e5 f5 g5 h5 i5)
      )
      (zone
         (name myside)
         (players Black)
         (positions a10 b10 c10 d10 e10 f10 g10 h10 i10
		            a9 b9 c9 d9 e9 f9 g9 h9 i9
					a8 b8 c8 d8 e8 f8 g8 h8 i8
					a7 b7 c7 d7 e7 f7 g7 h7 i7
					a6 b6 c6 d6 e6 f6 g6 h6 i6)
      )
   )

   (board-setup
      (Red
         (Soldier a4 c4 e4 g4 i4)
         (Horse b1 h1)
         (Elephant c1 g1)
         (Chariot a1 i1)
         (Mandarin d1 f1)
		 (Cannon b3 h3)
         (General e1)
      )
      (Black
         (Soldier a7 c7 e7 g7 i7)
         (Horse b10 h10)
         (Elephant c10 g10)
         (Chariot a10 i10)
         (Mandarin d10 f10)
		 (Cannon b8 h8)
         (General e10)
      )
   )

   (piece
      (name Soldier)
	  (help "兵/卒：向前一步，过河后可以横走一步。")
	  (description "兵/卒\兵在过河前只能向前一步。过河后除了向前，还可以横走一步。")
      (image Red "images\Chinese_Chess\RSoldier.bmp" "images\Chinese_Chess\Shaag\RSoldier.bmp" Black "images\Chinese_Chess\BSoldier.bmp" "images\Chinese_Chess\Shaag\BSoldier.bmp")
      (moves
         (n (verify not-friend?) add)
		 ((verify (not-in-zone? myside)) e (verify not-friend?) add)
		 ((verify (not-in-zone? myside)) w (verify not-friend?) add)
      )
   )
   (piece
      (name Horse)
      (help "马：走日。蹩腿。")
	  (description "马\
	    马跳日字，但若横向相邻点不为空格，那么马无法向那个方向跳，即“蹩马腿”。")
      (image Red "images\Chinese_Chess\RHorse.bmp" "images\Chinese_Chess\Shaag\RHorse.bmp" Black "images\Chinese_Chess\BHorse.bmp" "images\Chinese_Chess\Shaag\BHorse.bmp")
      (moves
	     (shift2 n ne)
	     (shift2 n nw)
	     (shift2 s se)
	     (shift2 s sw)
	     (shift2 e ne)
	     (shift2 e se)
	     (shift2 w nw)
	     (shift2 w sw)
      )
   )
   (piece
      (name Elephant)
      (help "象：飞田字。有塞眼限制。不可过河。")
	  (description "相/象\\象飞田字，但田字中间若有棋子，则象无法移动到那个方向，即“塞象眼”。象不可越过河界。\（另一表述方式：象可以斜走恰好两步，不可越子。）")
      (image Red "images\Chinese_Chess\RElephant.bmp" "images\Chinese_Chess\Shaag\RElephant.bmp" Black "images\Chinese_Chess\BElephant.bmp" "images\Chinese_Chess\Shaag\BElephant.bmp")
      (moves
         (shift-myside ne)
         (shift-myside nw)
         (shift-myside se)
         (shift-myside sw)
      )
   )
   (piece
      (name Chariot)
      (help "车：横直走不限。")
	  (description "车\\
	     车走法横直走不限。")
      (image Red "images\Chinese_Chess\RChariot.bmp" "images\Chinese_Chess\Shaag\RChariot.bmp" Black "images\Chinese_Chess\BChariot.bmp" "images\Chinese_Chess\Shaag\BChariot.bmp")
      (moves
         (slide n)
         (slide e)
         (slide s)
         (slide w)
      )
   )
   (piece
      (name Cannon)
      (help "炮：横直走不限，但吃子需隔一子。")
	  (description "炮\\
	     炮走子时与车相同。\炮吃子时，需间隔一个子（炮架）。")
      (image Red "images\Chinese_Chess\RCannon.bmp" "images\Chinese_Chess\Shaag\RCannon.bmp" Black "images\Chinese_Chess\BCannon.bmp" "images\Chinese_Chess\Shaag\BCannon.bmp")
      (moves
         (slide-cannon n)
         (slide-cannon e)
         (slide-cannon s)
         (slide-cannon w)
      )
   )
   (piece
      (name Mandarin)
      (image Red "images\Chinese_Chess\RMandarin.bmp" "images\Chinese_Chess\Shaag\RMandarin.bmp"
           Black "images\Chinese_Chess\BMandarin.bmp" "images\Chinese_Chess\Shaag\BMandarin.bmp")
	  (description "士\\
	     士只能在九宫内斜行一步。")
      (help "士：九宫内斜线走一步")
      (moves
         (shift-fortress ne)
         (shift-fortress nw)
         (shift-fortress se)
         (shift-fortress sw)
      )
   )
   (piece
      (name General)
      (image Red "images\Chinese_Chess\RGeneral.bmp" "images\Chinese_Chess\Shaag\RGeneral.bmp" Black "images\Chinese_Chess\BGeneral.bmp" "images\Chinese_Chess\Shaag\BGeneral.bmp")
      (help "将/帅：九宫内横直一步。不可与对方帅/将照面")
	  (description "帅/将\\
	   帅被将死即算输。帅的走法是九宫内横直一步。\双方的将帅不可处于无其他子阻挡的同一条纵线上，称为“照面”。")
      (moves
	     (opposed-kings)
         (shift-fortress n)
         (shift-fortress e)
         (shift-fortress s)
         (shift-fortress w)		 
      )
   )
   (loss-condition (Red Black) (checkmated General)  )
   (loss-condition (Red Black) stalemated )
   (loss-condition (Red Black) repetition )
)